%%Chapter 1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Guided exercises/demo}

\section{Guided exercises/demo}
In general, you will learn in this chapter how the Mininet-WiFi wireless network emulator works. Guided exercises will be explored and pointers to source code for those interested in delving deeper into the system architecture will be also provided. The pointers include stretches of the code where the link (including the latency) can be customized.


\subsection{Activity \themycounter{}: Warming up}   
\stepcounter{mycounter}

\noindent First of all, you have to stop the network-manager:

\begin{minted}{bash}
    sudo service network-manager stop 
\end{minted}


\noindent Then, create a simple topology with the command below:

\begin{minted}{bash}
    sudo mn --wifi
\end{minted}
	

\noindent The command above will start Mininet-WiFi and configure a small network with two stations, and one access point. Use the option {-}{-}topo of mn command, and discover further the topology options.

\noindent In Mininet-WiFi terminal (\textit{mininet-wifi>}), execute the command nodes to observe the created network. Then, execute iwconfig to verify the association between the stations and ap1.

\begin{minted}{bash}
    mininet-wifi>sta1 iwconfig
    mininet-wifi>sta2 iwconfig
    mininet-wifi>sta1 ping sta2
\end{minted}

	

\noindent Then, disconnect sta1 and confirm the disconnection:

\begin{minted}{bash}
    mininet-wifi>sta1 iw dev sta1-wlan0 disconnect
    mininet-wifi>sta1 iwconfig
    mininet-wifi>sta1 ping sta2
\end{minted}


\noindent Now, connect sta1 again: 

\begin{minted}{bash}
    mininet-wifi>sta1 iw dev sta1-wlan0 connect my-ssid
    mininet-wifi>sta1 iwconfig
    mininet-wifi>sta1 ping sta2
\end{minted}


\subsection{Activity \themycounter{}: Loading Network Topologies}

\noindent Running an example with the command below:
\begin{minted}{bash}
    sudo python examples/position.py
\end{minted}


\noindent Now, observe the position of sta1, sta2 and ap1:
\begin{minted}{bash}
    mininet-wifi>py sta1.params['position']
    mininet-wifi>py sta2.params['position']
    mininet-wifi>py ap1.params['position']
\end{minted}



\noindent Observe the signal power as well:
\begin{minted}{bash}
    mininet-wifi>py sta1.params['rssi']
    mininet-wifi>py sta2.params['rssi']
\end{minted}


\noindent If you prefer, you can see the distance between two nodes with the following command:

\begin{minted}{bash}
    mininet-wifi>distance sta1 ap1
    mininet-wifi>distance sta1 sta2   
\end{minted}


\noindent \textbf{$\ast$ Question \themycounter.\thequestion{}\stepcounter{question}: What is the observed bandwidth between sta1 and sta2?}
\\\textit{\textbf{Tip}: try iperf sta1 sta2}
\\

\noindent Now, move sta1 to another position:
\begin{minted}{bash}
    mininet-wifi>py sta1.setPosition('70,40,0')
\end{minted}


\noindent \textbf{$\ast$ Question \themycounter.\thequestion{}\stepcounter{question}: What happened with the association between sta1 and ap1?}
\\\textit{\textbf{Tip}: try sta1 iwconfig}
\\

\noindent Finally, increase the signal range of ap1:
\begin{minted}{bash}
    mininet-wifi>py ap1.setRange(60)
\end{minted}


\noindent \textbf{$\ast$ Question \themycounter.\thequestion{}\stepcounter{question}: What happened with the association between sta1 and ap1 now?}

\noindent \textbf{$\ast$ Question \themycounter.\thequestion{}\stepcounter{question}: Now, observe the bandwidth between sta1 and sta2 again. 
What can we conclude?  }


\stepcounter{mycounter}
\setcounter{question}{1}
\subsection{Activity \themycounter{}: Customizing the Wireless Channel}
	
Mininet-WiFi relies on the configuration of Linux TC (by default) to
control the wireless channel properties, such as \textit{bandwidth}, \textit{packet loss}, \textit{delay} and \textit{latency}. Please see the equations in \textit{mininet/wifiLink.py} (refer to equationBW, equationLoss, equationDelay and equationLatency. Those equations can be customized by calling setChannelEquation(), for example:

\begin{minted}[breaklines]{bash}
    net.setChannelEquation(bw='value.rate * (1.1 ** -dist)', loss='(dist * 2)/100', delay='(dist / 10) + 1', latency='2 + dist')
\end{minted}

Alternatively, a new approach called wmediumd has been implemented, a wireless medium simulation tool for Linux, based on the netlink API implemented in the mac80211\_hwsim kernel driver. A couple of sample files that use wmediumd are available at /examples.\\

\noindent \textbf{$\ast$ Question \themycounter.\thequestion{}\stepcounter{question}: Run position.py again and try \textit{sta1 tc qdisc} before and after moving sta1 to the new position. What do you can conclude about the configuration applied by tc?}
\\


%%Chapter 2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Further hands-on}
(Further hands-on exercises proposed to be carried by the attendees on their own and at their pace.
	A number practical exercises will be proposed where mobility and/or distance (or poor signal) among mobile nodes may impact latency and bandwidth, consequently the communication between two nodes.)


\stepcounter{mycounter}
\setcounter{question}{1}
\subsection{Activity \themycounter{}: Mobility}  


\noindent Open examples/mobilityModel.py with any text editor and change the velocity of stations as below:
\begin{minted}[breaklines]{bash}
   from: net.startMobility(time=0, model='RandomDirection', max_x=100, max_y=100, min_v=0.5, max_v=0.8)
   to: net.startMobility(time=0, model='RandomDirection', max_x=100, max_y=100, min_v=0.1, max_v=0.1)
\end{minted}

\noindent Run examples/mobilityModel.py and change the signal range of ap1:
\begin{minted}{bash}
    python examples/mobilityModel.py
    mininet-wifi>py ap1.setRange(60)
\end{minted}

\noindent Then, ping sta1 and sta2:
\begin{minted}{bash}
    mininet-wifi>sta1 ping sta2
\end{minted}

\noindent \textbf{$\ast$ Question \themycounter.\thequestion{}\stepcounter{question}: What can you conclude about the latency?}\\
\textit{\textbf{Tip:} you can issue sta1 tc qdisc, repeatedly, to see the values applied by tc.}


\stepcounter{mycounter}
\setcounter{question}{1}
\subsection{Activity \themycounter{}: Received Signal Strength} 

\noindent Open examples/position.py with any text editor and add sta3 at position='10,10,10' and set max\_z=100 in order to plot a 3d graph. Then, run examples/position.py.\\

\noindent \textbf{$\ast$ Question \themycounter.\thequestion{}\stepcounter{question}: What is the received signal strength indicator (RSSI) observed from sta3?}
\\
\\
\noindent \textbf{$\ast$ Question \themycounter.\thequestion{}\stepcounter{question}: What is the average ping response time between sta2 and sta1? And sta3 and sta1? \textit{Note: define the number of packets to 10 (ping -c10)}.}


%%Chapter 3
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{OpenFlow}
You will learn with this activity some basic concepts of the OpenFlow protocol, such as idle/hard timeout and identify the impact of the mobility in the communication. 

\stepcounter{mycounter}
\setcounter{question}{1}
\subsection{Activity \themycounter{}: Mobility and OpenFlow}

\noindent First of all you have to get the code from \url{https://github.com/ramonfontes/reproducible-research/blob/master/mininet-wifi/ACROSS-Sweden-2017/handover.py} and then run it with the command below (the content of handover.py is also available in \autoref{code-handover}):

\begin{minted}{bash}
    sudo python handover.py
\end{minted}

\noindent Now, keep h1 pinging to sta1
\begin{minted}{bash}
    mininet-wifi>h1 ping sta1
\end{minted}

\noindent \textbf{$\ast$ Question \themycounter.\thequestion{}\stepcounter{question}: As you can see, h1 cannot reach sta1 when sta1 goes to ap2. Why? Two important commands should help you to answer this question:}

\begin{minted}{bash}
    mininet-wifi>links 
    mininet-wifi>sh ovs-ofctl dump-flows s3 
\end{minted}
\textit{\textbf{Tip:} Observe both idle\_timeout and idle\_age.}\\

\noindent \textbf{$\ast$ Question \themycounter.\thequestion{}\stepcounter{question}: Now you know the answer to Question 6.1, how could sta1 be reached by h1?}